package com.hhs.storage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hhs.storage.bean.ContractProductSupplier;
import com.hhs.storage.bean.InputParam;
import com.hhs.storage.bean.ProductSupplier;
import com.hhs.storage.dao.ContractProductSupplierDao;
import com.hhs.storage.service.ContractProductSupplierService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hhs.storage.service.ProductSupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author hhs
 * @since 2023-01-04
 */
@Service
@Transactional
public class ContractProductSupplierServiceImpl extends ServiceImpl<ContractProductSupplierDao, ContractProductSupplier> implements ContractProductSupplierService {
    @Autowired
    private ProductSupplierService productSupplierService;

    @Override
    public Map<String, Object> getProductSuppliersByContractId(String contractId) {
        QueryWrapper ew = new QueryWrapper<ContractProductSupplier>();
        ew.like("contract_id",contractId);
        List<ContractProductSupplier> list=this.baseMapper.selectList(ew);
        List<ProductSupplier> data=new ArrayList<>();
        for (int i = 0; i <list.size() ; i++) {
            String id=list.get(i).getProductSupplierId();
            data.add(productSupplierService.getById(id));
        }
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("rows", data);
        map.put("code", 1);
        return map;
    }
}
